package com.javaspeak.designpatterns.go4.behavioural.command;

import java.util.HashMap;
import java.util.Map;

/**
 * This Command class reads in a map of request attributes from the request and
 * for each of the request attributes capitalises the value and returns them in
 * a new map which is passed to the handleResponse(..) method.
 *
 * @author John Dickerson
 */
public class CapitaliseCommand implements Command {

    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.command.Command#
     *     execute(com.javaspeak.designpatterns.go4.behavioural.command.Request,
     *      com.javaspeak.designpatterns.go4.behavioural.command.Response)
     */
    @Override
    public void execute(Request request, Response response) {

        Map<String,String> requestAttributes = request.getRequestAttributes();
        Map<String,String> responseAttributes = new HashMap<String,String>();

        for ( String key : requestAttributes.keySet() ){

            responseAttributes.put( key ,
                    requestAttributes.get( key ).toUpperCase() );
        }

        response.handleResponse( responseAttributes );
    }
}
